package com.race;

/**
 * Created by iss on 2018/3/29.
 */
public class BST {

    static class BNode {
        private int data;
        private BNode parent;
        private BNode left;
        private BNode right;

        public BNode(int data, BNode parent, BNode left, BNode right) {
            this.data = data;
            this.parent = parent;
            this.left = left;
            this.right = right;
        }
    }

    BNode findMin(BNode root) {
        if (root == null) {
            return null;
        }

        if (root.left != null) {
            return findMin(root.left);
        }

        return root;
    }

    BNode findMax(BNode root) {
        if (root == null) {
            return null;
        }

        while (root.right != null) {
            root = root.right;
        }

        return root;
    }

}
